package com.webdev.servlet;

import java.io.IOException;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.webdev.domain.Request;
import com.webdev.service.RequestService;
import com.webdev.service.imp.RequestServiceImp;

/**
 * Servlet implementation class AddRequestServlet
 */
@WebServlet("/AddRequestServlet")
public class AddRequestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	/*处理提交的请假请求*/
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Request req = new Request();
		try {
			req.setRsdate(new Date(sdf.parse(request.getParameter("rsdate")).getTime()));
			req.setRedate(new Date(sdf.parse(request.getParameter("redate")).getTime()));
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		req.setRtype(request.getParameter("rtype"));
		if(!request.getParameter("rinfo").equals("[object HTMLInputElement]")) {
		    req.setRinfo(request.getParameter("rinfo"));
		}
		else {
			req.setRinfo("无");
		}
		req.setPid(Integer.parseInt(request.getParameter("pid")));
		
		RequestService service = new RequestServiceImp();
		service.addRequest(req);
	}

}
